﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Xml;
using System.IO;

namespace TDT_Project.classes
{
    public class cls_user_dang_nhap
    {
        int _id_login = 0;

        public int ID_Login
        {
            get { return _id_login; }
            set { _id_login = value; }
        }

        Int32 _IDLogin=0;

        public Int32 IDLogin
        {
            get { return _IDLogin; }
            set { _IDLogin = value; }
        }

        string _GiaoVienID = "";

        public string GiaoVienID
        {
            get { return _GiaoVienID; }
            set { _GiaoVienID = value; }
        }

        string _Username = "";

        public string Username
        {
            get { return _Username; }
            set { _Username = value; }
        }

        string _pass = "";

        public string pass
        {
            get { return _pass; }
            set { _pass = value; }
        }

        int _BiVoHieu = 0;

        public int BiVoHieu
        {
            get { return _BiVoHieu; }
            set { _BiVoHieu = value; }
        }

        int _LoaiNguoiDung_ID = 0;

        public int LoaiNguoiDung_ID
        {
            get { return _LoaiNguoiDung_ID; }
            set { _LoaiNguoiDung_ID = value; }
        }


        int _spid = 0;

        public int spid
        {
            get { return _spid; }
            set { _spid = value; }
        }

        public DataSet Get_Thong_Tin_Giao_Vien_Toan_123()
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("Get_Thong_Tin_Giao_Vien_Toan_123", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }
        public DataSet Get_NhanXet_PH_For_GV(string @Lop_Id, string @NienHoc_id, string @HocKy_ID, int @Loai_NX)
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("Get_NhanXet_PH_For_GV", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@Lop_Id", SqlDbType.NChar).Value = @Lop_Id;
            oCommand.Parameters.Add("@NienHoc_id", SqlDbType.NChar).Value = @NienHoc_id;
            oCommand.Parameters.Add("@HocKy_ID", SqlDbType.NChar).Value = @HocKy_ID;
            oCommand.Parameters.Add("@Loai_NX", SqlDbType.NChar).Value = @Loai_NX;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }

        public bool Toan_Insert_user_login_web()
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("Toan_Insert_user_login_web", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;            
            oCommand.Parameters.Add("@GiaoVienID", SqlDbType.NVarChar).Value = GiaoVienID;
            oCommand.Parameters.Add("@Username", SqlDbType.NVarChar).Value = Username;
            oCommand.Parameters.Add("@pass", SqlDbType.NVarChar).Value = pass;
            oCommand.Parameters.Add("@LoaiNguoiDung_ID", SqlDbType.NVarChar).Value = LoaiNguoiDung_ID;
            oCommand.Parameters.Add("@BiVoHieu", SqlDbType.Int).Value = BiVoHieu;
            oCommand.Parameters.Add("@spid", SqlDbType.Int).Value = spid;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }


        public bool TOAN_Update_user_login_web_Toan()
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Update_user_login_web_Toan", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;           
            oCommand.Parameters.Add("@IDLogin", SqlDbType.BigInt).Value = ID_Login;
            oCommand.Parameters.Add("@GiaoVienID", SqlDbType.NVarChar).Value = GiaoVienID;
            oCommand.Parameters.Add("@Username", SqlDbType.NVarChar).Value = Username;
            oCommand.Parameters.Add("@pass", SqlDbType.NVarChar).Value = pass;
            oCommand.Parameters.Add("@LoaiNguoiDung_ID", SqlDbType.Int).Value = LoaiNguoiDung_ID;
            oCommand.Parameters.Add("@BiVoHieu", SqlDbType.Int).Value = BiVoHieu;
            oCommand.Parameters.Add("@spid", SqlDbType.Int).Value = spid;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }
        public int TOAN_Update_user_login_web_Toan_changepass(string @Username, string @pass, string @newpass)
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Update_user_login_web_Toan_changepass", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;         
            oCommand.Parameters.Add("@Username", SqlDbType.NVarChar).Value = Username;
            oCommand.Parameters.Add("@pass", SqlDbType.NVarChar).Value = pass;
            oCommand.Parameters.Add("@newpass", SqlDbType.NVarChar).Value = @newpass;  
            int bReturn = 0;
            try
            {
                oConnection.Open();
                bReturn = (int)oCommand.ExecuteScalar();
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }

        public DataSet TOAN_getall_user_login_web()
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_getall_user_login_web", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }
        public DataSet TOAN_getall_user_login_web_by_username(string username)
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_getall_user_login_web_by_username", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@Username", SqlDbType.NVarChar).Value = username;           
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }

        public DataSet TOAN_Check(string giaovienid, string username)
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Check-user_Toan", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@GiaoVienID", SqlDbType.NVarChar).Value = giaovienid;
            oCommand.Parameters.Add("@Username", SqlDbType.NVarChar).Value = username;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;

        }

        public DataSet TOAN_getall_user_login_web_ID(int IDLogin)
        {
            DataSet results = new DataSet();
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_getall_user_login_web_ID", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@IDLogin ", SqlDbType.Int).Value = IDLogin;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = oCommand;
            da.Fill(results);

            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return results;
        }


        public bool TOAN_Delete_user_login_web(int IDLogin)
        {
            SqlConnection oConnection = new SqlConnection(cls_config.ConnectionString);
            SqlCommand oCommand = new SqlCommand("TOAN_Delete_user_login_web", oConnection);
            oCommand.CommandType = CommandType.StoredProcedure;
            oCommand.Parameters.Add("@IDLogin", SqlDbType.Int).Value = IDLogin;
            bool bReturn = false;
            try
            {
                oConnection.Open();
                oCommand.ExecuteNonQuery();
                bReturn = true;
            }
            catch
            {
                return bReturn;
            }
            oConnection.Close();
            oConnection.Dispose();
            oConnection = null;
            return bReturn;
        }
    }
}